<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>

    </div>

    <script>
        var arr = [12, 18, 24, 36, 57]

        Array.prototype.myForEach = function (fn) {
            for (var i = 0; i < this.length; i++) {
                fn(this[i], i)
            }
        }

        arr.myForEach(function (item, i) {
            // console.log('item' + item, 'i' + i);
        })

        // function myAjax(type,url,fn){
        //     var xhr =new XMLHttpRequest()
        //     xhr.open(type,url,true)
        //     xhr.send()
        //     xhr.onreadystatechange = function(){
        //         if(xhr.readyState == 4 && xhr.status == 200){
        //             fn(xhr.responseText)
        //         }
        //     }
        // }

        // myAjax('GET','./1.json',function(res){
        //     // console.log(res);
        // })

        function myAjax(type, url) {
            var p = new Promise(function (resolve, reject) {
                var xhr = new XMLHttpRequest()
                xhr.open(type, url, true)
                xhr.send()
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        resolve(xhr.responseText)
                    }
                }
            })
            return p
        }
        // myAjax('GET', './1.json').then(res => {
        //     console.log(res);
        // })

        let a = myAjax('GET', './1.json')
        let b = myAjax('GET', './2.json')

        Promise.all([a,b]).then(res=>{
            console.log(res);
        })

        Promise.race([a,b]).then(res=>{
            console.log(res);
        })

            
    </script>
</body>

</html>